package com.zyasdk.service;

import android.content.Context;
import android.util.Base64;
import android.util.Log;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Activate Statistics
 * 
 */
public class PidCidService extends BaseService {
	public PidCidService(Context context) {
		super(context);
	}
	
	public void AddPidCid(final String pBindKey,final String packid,final String cid) {
		if(pBindKey==null || packid==null || cid==null) return;
        JSONObject json = null;
        try {
        	json = new JSONObject();
            json.put("accesstype","1");
            json.put("packetid",packid);
            json.put("action","1");
            json.put("clientid",cid);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        
        if(json != null){
        	List<NameValuePair> params = new ArrayList<NameValuePair>();
    		params.add(new BasicNameValuePair("PBindKey", pBindKey));
    		params.add(new BasicNameValuePair("data",Base64.encodeToString(json.toString().getBytes(), Base64.DEFAULT)));
            Log.i("result", "AddPidCid ");
            ServiceTask.addTask(GetAPIUrl("UnifiedAccess"), params);
        }
	}
	
	public void DelPidCid(final String pBindKey,final String packid,final String cid) {
		if(pBindKey==null || packid==null || cid==null) return;
        JSONObject json = null;
        try {
        	json = new JSONObject();
            json.put("accesstype","1");
            json.put("packetid",packid);
            json.put("action","0");
            json.put("clientid",cid);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        
        if(json != null){
        	List<NameValuePair> params = new ArrayList<NameValuePair>();
    		params.add(new BasicNameValuePair("PBindKey", pBindKey));
    		params.add(new BasicNameValuePair("data",Base64.encodeToString(json.toString().getBytes(), Base64.DEFAULT)));
            Log.i("result", "DelPidCid ");
            ServiceTask.addTask(GetAPIUrl("UnifiedAccess"), params);
        }
	}
}
